/**
  * 换头像页面
  */
module game {

    export class SpeciaModifyMediator extends BaseMediator {
        public static NAME: string = "SpeciaModifyMediator";
        public constructor(viewComponent: any = null) {
            super(SpeciaModifyMediator.NAME, viewComponent);
        }

        public listNotificationInterests(): Array<any> {
            return [
                PanelNotify.HALL.STAGE_RESIZE,
                PanelNotify.HALL.OPEN_SPECIA_MODIFY,
                PanelNotify.HALL.CLOSE_SPECIA_MODIFY
            ];
        }
        private panel: SpeciaModifyPanel;
        public handleNotification(notification: puremvc.INotification): void {
            switch (notification.getName()) {
                case PanelNotify.HALL.STAGE_RESIZE:
                    if (this.panel) {
                        this.panel.width = GameConfig.curWidth()
                        this.panel.height = GameConfig.curHeight()
                    }
                    break;
                case PanelNotify.HALL.OPEN_SPECIA_MODIFY:
                    //显示角色面板
                    this.panel = null;
                    this.panel = new SpeciaModifyPanel();
                    this.showUI(this.panel, 2, 1, true);
                    break;
                case PanelNotify.HALL.CLOSE_SPECIA_MODIFY:
                    this.closePanel(1);
                    break;
            }
        }

        /**
         * 初始化面板ui
         */
        public initUI(): void {
            this.panel.closeBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onCloseBntClick, this);

        }
        /**
         * 初始化面板数据
         */
        public initData(): void {
            this.panel.special_0.addEventListener(egret.TouchEvent.TOUCH_TAP, this.modifyClick, this);
            let num = this.panel.special_group.numChildren;
            for (let i = 0; i < num; i++) {
                this.panel.special_group.getChildAt(i).name = i + "";
                this.panel.special_group.getChildAt(i).addEventListener(egret.TouchEvent.TOUCH_TAP, this.modifyClick, this)
            }
        }
        private modifyClick(event: egret.TouchEvent) {
            EffectUtils.playDim(event.currentTarget)
            var name = event.currentTarget.name;
            let obj = {
                wFaceID: name,
                dwUserID: GameVO.getVo().dwUserID,
                szPassword: GameVO.getVo().szDynamicPass,
                szMachineID: ""
            }
            SocketManager.sendMessage(InstructionsEnum.GAME_TYPE_NAME.HALL, RegDataGame.CMD_C_CustomFaceInfo, obj)
        }
        private onCloseBntClick(event: egret.TouchEvent): void {
            SoundManage.startAnniuBtnLoad();
            this.closePanel(1);
        }
    }
}